Socket
Socket
Sign inDemoInstall

aggregate-error

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aggregate-error

Create an error from multiple errors


Version published
Weekly downloads
26M
decreased by-1.3%
Maintainers
1
Weekly downloads
 
Created

What is aggregate-error?

The aggregate-error package is used to create an Error instance that aggregates multiple errors into a single error object. This can be useful when you have several operations that may each throw errors, and you want to collect all of those errors into a single error object that can be thrown, returned, or logged.

What are aggregate-error's main functionalities?

Aggregating multiple errors

This feature allows you to collect multiple errors into a single error object. The code sample demonstrates how to create an instance of AggregateError with an array of Error objects and then throw it.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

throw aggregatedError;

Iterating over aggregated errors

This feature allows you to iterate over the individual errors within an AggregateError instance. The code sample shows how to loop through each error using a for...of loop and log them to the console.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

for (const error of aggregatedError) {
  console.error(error);
}

Other packages similar to aggregate-error

Keywords

FAQs

Package last updated on 14 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc